package com.chinatelecom.framework.model;

import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

@ApiModel("分页数据对象")
@Getter
@Setter
public class PageData<T> extends PageParam {

	private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "数据实体")
	private List<T> list;

	public PageData() {
	}

	/**
	 * 用于本地数据分页
	 */
	public PageData(List<T> data) {
		if (data != null) {
			this.page = 1;
			this.totalPage = 1;
			this.totalCount = data.size();
			this.list = data;
		}
	}

	public PageData(IPage<T> data, PageParam param) {
		if (data != null) {
			int totalPage = (int) (data.getTotal() / param.getPageSize());

			if (data.getTotal() % param.getPageSize() == 0)
				this.totalPage = totalPage;
			else
				this.totalPage = totalPage + 1;

			this.page = param.getPage();
			this.totalCount = (int) data.getTotal();
			this.list = data.getRecords();
		}
	}

}
